﻿@using System.Web.Optimization
@inherits VocaDb.Web.Code.VocaDbPage<VocaDb.Model.DataContracts.Artists.ArtistContract>

@{
    PageProperties.Title = "Merge artist - " + Model.Name;
	ViewBag.Parents = new[] { 
		Html.ActionLink("Artists", "Index"), 
		Html.ActionLink(Model.Name, "Details", new { id = Model.Id }),
		Html.ActionLink("Edit", "Edit", new { id = Model.Id }),
	};	
}

@using (Html.BeginForm()) {

	@Helpers.MergeEntryInfo()

	<input type="hidden" name="targetArtistId" id="targetArtistId" data-bind="value: target.id" />

	<br />
	<div class="clearfix">
		<div class="pull-left">
			@KnockoutHelpers.LockingAutoComplete("artistAutoComplete", "targetSearchParams", "target.name", "target.id")
		</div>
		<div class="pull-left entry-field-inline-warning">
			<div class="alert" data-bind="visible: validationError_targetIsNewer" style="display: none;">
				<span class="icon-line errorIcon"></span>
				@ViewRes.EntryMergeStrings.ValidationErrorTargetIsNewer
			</div>

			<div class="alert" data-bind="visible: validationError_targetIsLessComplete" style="display: none;">
				<span class="icon-line errorIcon"></span>
				@ViewRes.EntryMergeStrings.ValidationErrorTargetIsLessComplete
			</div>
		</div>
	</div>

	<br />

	<button type="submit" class="btn btn-primary" id="mergeBtn" data-bind="enable: target.id">@ViewRes.EntryMergeStrings.MergeBtnText</button>

}

@section BodyScripts {
	@Scripts.Render("~/bundles/shared/edit", "~/bundles/Artist/Merge")
	<script type="text/javascript">

		$(function() {

			var repoFactory = new vdb.repositories.RepositoryFactory(new vdb.UrlMapper('@RootPath'), @LanguagePreferenceInt);
			var repo = repoFactory.artistRepository();
			var vm = new vdb.viewModels.artists.ArtistMergeViewModel(repo, @Model.Id);
			ko.applyBindings(vm);

			$("#mergeBtn").click(function () {
				return confirm("Are you sure you want to merge the artists?");
			});

		});

	</script> 
}
